package com.example.spring.exercise.controller;

import com.example.spring.exercise.service.dto.BaseClassInfo;
import com.example.spring.exercise.service.dto.StudentDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

/**
 * @author : zhayh
 * @date : 2021-3-13 15:23
 * @description : 第1单元测试
 * 验证URL： http://coursescore.nj-agile.com/#/pages/index/index
 */

@RestController
@RequestMapping("/api")
@Api(tags = "第1单元的API")
public class Unit1Controller {
    @ApiOperation(value = "HelloWorld返回常量")
    @GetMapping("/helloworld")
    public ResponseEntity<String> hello() {
        return ResponseEntity.ok("Hello world.");
    }

    @ApiOperation("HelloWorld返回自定义对象")
    @GetMapping("/helloworld/student")
    public ResponseEntity<StudentDTO> getStudentInfo() {
        BaseClassInfo classInfo = BaseClassInfo.builder()
                .classCode("1902783")
                .className("移动1923")
                .classYear(2019)
                .build();
        //定义返回的学生对象
        StudentDTO result = StudentDTO.builder()
                .studentCode("1902783201")
                .studentName("张海")
                .classInfo(classInfo)
                .roommates(new ArrayList<>() {{
                    add(StudentDTO.builder().studentCode("1902783202").studentName("王晓").classInfo(classInfo).build());
                    add(StudentDTO.builder().studentCode("1902783203").studentName("李艳").classInfo(classInfo).build());
                }})
                .build();
        return ResponseEntity.ok(result);
    }

}
